﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DriverExtendedNotifications
{
    class EmailMessage
    {
        private string content;
        public EmailMessage(string InputContent)
        {
            this.content = InputContent;
        }

        #region Methods to get email message details
        public string GetFrom()
        {
            String messTop=content; 
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nFrom:") + 7));
            messTop = messTop.Remove(messTop.IndexOf('\r'), ((messTop.Length - messTop.IndexOf('\r')) - 1));
            return messTop;
        }

        public string GetDate()
        {
            String messTop = content; 
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nDate:") + 7));
            messTop = messTop.Remove(messTop.IndexOf('\r'), (messTop.Length - messTop.IndexOf('\r')));
            return messTop;
        }

        public string GetMessID()
        {
            String messTop = content; 
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nMessage-ID: ") + 13));
            messTop = messTop.Remove(messTop.IndexOf('\r'), (messTop.Length - messTop.IndexOf('\r')));
            return messTop;
        }

        public string GetTo()
        {
            String messTop = content; 
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nTo:") + 6));
            messTop = messTop.Remove(messTop.IndexOf('\r'), (messTop.Length - messTop.IndexOf('\r')));
            return messTop;
        }

        public string GetSubject()
        {
            String messTop = content; 
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nSubject:") + 10));
            messTop = messTop.Remove(messTop.IndexOf('\r'), (messTop.Length - messTop.IndexOf('\r')));
            return messTop;
        }

        public string GetBody()
        {
            String messTop = content;
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\nContent-Type: text/plain") + 26));
            messTop = messTop.Remove(0, (messTop.IndexOf("\r\n.\r\n") + 3));
            messTop = messTop.Remove(messTop.IndexOf("\r\n--"), messTop.Length - messTop.IndexOf("\r\n--"));
                
            return messTop;
        }
        #endregion

    }
}
